package com.lc.command;

import com.lc.protocol.DeviceError;

import org.json.JSONObject;

/**
 * Created by zhyioo on 2017/8/7.
 */

public class ComplexCommand implements ICommand {
    protected ICommandDriver _driver = null;
    protected String _cmd = "";

    public ComplexCommand() {}

    public ComplexCommand(ICommandDriver driver, String cmd) {
        Make(driver, cmd);
    }

    public boolean Make(ICommandDriver driver, String cmd) {
        _driver = driver;
        _cmd = cmd;
        return IsValid();
    }

    public String Name() {
        return _cmd;
    }

    public boolean IsValid() {
        return _driver != null;
    }

    @Override
    public boolean Run(JSONObject arg, JSONObject rlt) {
        if(_driver == null) {
            CommandActuator.LogErr(rlt, DeviceError.ArgIsNullErr, "CommandDriver is null");
            return false;
        }
        return _driver.OnCommand(_cmd, arg, rlt);
    }
}
